package com.atguigu.flink.chapter5.transform;

import com.atguigu.flink.WaterSensor;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/19 14:56
 */
public class Flink10_Transform_RollingAggregate {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        env
          .socketTextStream("hadoop162", 9999)
          .map(line -> {
              String[] split = line.split(",");
              return new WaterSensor(split[0], Long.valueOf(split[1]), Integer.valueOf(split[2]));
          })
          .keyBy(WaterSensor::getId)
          //.sum("vc")
          //.max("vc")
          .maxBy("vc",false)
          .print();

        env.execute();
    }
}
/*
sum
    其他值永远选的是第一次碰到的那个元素的值
max min
    也是

maxBy minBy
    其他值选的和最大值所在的那条数据的值. 如果出现相同的最大值: 如果true就选第一个, false选择最后
 */
